<?php
$passid = $this->params['pass'];
$breadcrumsubc = $this->requestAction('/products/breadcrumchkHasParent/' . $passid[0]);
if ($breadcrumsubc['label'] == 1) {
    $this->Html->addCrumb($breadcrumsubc['catname_label1'], '/products/browsebycategory/' . $breadcrumsubc['catid_label1'], array('escape' => false));
} elseif ($breadcrumsubc['label'] == 2) {
    $this->Html->addCrumb($breadcrumsubc['catname_label1'], '/products/browsebycategory/' . $breadcrumsubc['catid_label1'], array('escape' => false));
    $this->Html->addCrumb($breadcrumsubc['catname_label2'], '/products/browsebycategory/' . $breadcrumsubc['catid_label2'], array('escape' => false));
} elseif ($breadcrumsubc['label'] == 3) {
    $this->Html->addCrumb($breadcrumsubc['catname_label1'], '/products/browsebycategory/' . $breadcrumsubc['catid_label1'], array('escape' => false));
    $this->Html->addCrumb($breadcrumsubc['catname_label2'], '/products/browsebycategory/' . $breadcrumsubc['catid_label2'], array('escape' => false));
    $this->Html->addCrumb($breadcrumsubc['catname_label3'], '/products/browsebycategory/' . $breadcrumsubc['catid_label3'], array('escape' => false));
} elseif ($breadcrumsubc['label'] == 4) {
    $this->Html->addCrumb($breadcrumsubc['catname_label1'], '/products/browsebycategory/' . $breadcrumsubc['catid_label1'], array('escape' => false));
    $this->Html->addCrumb($breadcrumsubc['catname_label2'], '/products/browsebycategory/' . $breadcrumsubc['catid_label2'], array('escape' => false));
    $this->Html->addCrumb($breadcrumsubc['catname_label3'], '/products/browsebycategory/' . $breadcrumsubc['catid_label3'], array('escape' => false));
    $this->Html->addCrumb($breadcrumsubc['catname_label4'], '/products/browsebycategory/' . $breadcrumsubc['catid_label4'], array('escape' => false));
}
?>

<div class="products">
    <div class="search-title"><?php __('BROWSE BY CATEGORY'); ?></div>
    <div class="rht-con">
        <div class="mdl-con widthstyle1" style="width:100%;">
            <div class="porduct-browse"   style="width:100%;">
                <div class="search_result">Showing results for<i style="color: #808080;">
                        <?php
                        $schterm = $this->requestAction('/products/getnamebyid/' . $passid[0]);
                        echo '"' . $schterm['Category']['category_name'] . '"';
                        ?>
                    </i>
                </div>
                <?php
                if (!empty($products)) {
                    echo count($products);
                } else {
                    echo '0';
                }
                ?> results found.
                <?php
                if (!empty($products)) {
                    ?>
                    <?php $urlparam = $this->params['pass'];?>
                    <div class="result">
                        <div class="container">
                            <?php if (empty($thumb)) { ?>
                                <a href="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0] . '/thumb?keywords='.$searchkey; ?>&query=<?php echo $query;?>" class="switch_thumb1">Switch Thumb</a>
                            <?php } else { ?>
                                <a href="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0].'?keywords='.$searchkey; ?>&query=<?php echo $query;?>" class="switch_thumb1 swap">Switch Thumb</a>
                            <?php } ?>
                            <span style="float:right; line-height:26px;">Sort by:
                                 <?php if (empty($thumb)) { ?>
                                <select name="sortby" id="dynamic_select">
                                    <option value="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0] . '/1?keywords='.$searchkey; ?>&query=<?php echo $query;?>'" <?php
                                    if (isset($urlparam[1]) AND $urlparam[1] == 1) {
                                        echo 'selected';
                                    }
                                    ?>>Time: Ending soonest</option>
                                    <option value="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0] . '/2?keywords='.$searchkey; ?>&query=<?php echo $query;?>'" <?php
                                        if (isset($urlparam[1]) AND $urlparam[1] == 2) {
                                            echo 'selected';
                                        }
                                     ?>>Time: Newly Listed</option>
                                    <option value="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0] . '/3?keywords='.$searchkey; ?>&query=<?php echo $query;?>'" <?php
                                    if (isset($urlparam[1]) AND $urlparam[1] == 3) {
                                        echo 'selected';
                                    }
                                    ?>>Price: Highest</option>
                                    <option value="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0] . '/4?keywords='.$searchkey; ?>&query=<?php echo $query;?>" <?php
                                    if (isset($urlparam[1]) AND $urlparam[1] == 4) {
                                        echo 'selected';
                                    }
                                    ?>>Price: Lowest</option>
                                </select>
                                <?php }else{?>
                                <select name="sortby" id="dynamic_select">
                                    <option value="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0] . '/thumb/1?keywords='.$searchkey; ?>&query=<?php echo $query;?>'" <?php
                                    if (isset($urlparam[2]) AND $urlparam[2] == 1) {
                                        echo 'selected';
                                    }
                                    ?>>Time: Ending soonest</option>
                                    <option value="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0] . '/thumb/2?keywords='.$searchkey; ?>&query=<?php echo $query;?>'" <?php
                                        if (isset($urlparam[2]) AND $urlparam[2] == 2) {
                                            echo 'selected';
                                        }
                                     ?>>Time: Newly Listed</option>
                                    <option value="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0] . '/thumb/3?keywords='.$searchkey; ?>&query=<?php echo $query;?>'" <?php
                                    if (isset($urlparam[2]) AND $urlparam[2] == 3) {
                                        echo 'selected';
                                    }
                                    ?>>Price: Highest</option>
                                    <option value="<?php echo Configure::read('base_url') . 'products/browsebycategory/' . $urlparam[0] . '/thumb/4?keywords='.$searchkey; ?>&query=<?php echo $query;?>'" <?php
                                    if (isset($urlparam[2]) AND $urlparam[2] == 4) {
                                        echo 'selected';
                                    }
                                    ?>>Price: Lowest</option>
                                </select>
                                <?php }?>
                            </span>									
                            <div id="Searchresult">
                                 <?php if (empty($thumb)) { ?>
                                    <div class="days_left"><span style="text-align:center; margin-left: 185px;"><b>Title</b></span><span style="text-align:right; margin-left: 565px;margin-right:50px;"><b>ID</b></span><b>Price</b><b style="margin-left:60px">Days Left</b></div>
                                    <ul class="display"></ul>
                                 <?php } else { ?>	
                                    <ul class="display thumb_view"></ul>
                                 <?php } ?>
                            </div>
                        </div>
                    </div>								
                    <!-- Container element for all the Elements that are to be paginated -->
                    <div id="hiddenresult" style="display:none;">
                        <ul class="display">
                            <?php
                            if (!empty($products)) {
                                $i = 0;
                                foreach ($products as $product):
                                    $class = null;
                                    if ($i++ % 2 == 0) {
                                        $class = ' class="altrow"';
                                    }
                                    ?>
                                    <li>
                                        <div class="content_block">
                                            <div><a class="thumb_mouse_out" href="javascript:void(0);" controller="products" action="gallery_popup" ElmID="<?php echo $product['Product']['id']; ?>" alignLeft="1" onmouseover="showPop1(this)">
                                            <?php
                                            $image = "thumbs/";
                                            echo $html->image($image . $thumbnail->render($product['Product']['products_thumbnailImage'], array('path' => 'thumbs', 'width' => 140, 'height' => 140, 'quality' => 80)
                                                    ), array('alt' => $product['Product']['products_title'])
                                            );
                                            ?>
                                                </a>

                                            </div>
                                <?php
                                if (empty($thumb))
                                    echo"<h2>";else
                                    echo"<h2 style='width:240px;'>";
                                ?><a href="<?php echo Configure::read('base_url'); ?>products/details/<?php echo $product['Product']['id']; ?>"><?php echo $product['Product']['products_title']; ?></a></h2>
                                            <p><span style="width:95px;"><a href="<?php echo Configure::read('base_url'); ?>products/store/<?php echo $product['User']['id']; ?>"><?php echo $product['User']['username']; ?></a></span> <span><?php echo 'US $' . $product['Product']['products_price']; ?></span> <span><?php echo $product[0]['totaldays']; ?> days</span></p>
                                        </div>
                                    </li>
        <?php endforeach; ?>
                            </ul>
                                <?php
                            }else {
                                echo 'No data Found!';
                            }
                            ?>
                    </div>
                    <div id="viewNumPageItem">
                        <span style="float:left; display:block;">Items per page:&nbsp;&nbsp;</span>
                        <ul class="newinline">
                            <li><a href="#25" >25</a></li>
                            <?php
                            if (count($products) >= 50) {
                                ?>
                                <li><a href="#50" >50</a></li>
                                <?php
                            }
                            ?>
                            <?php
                            if (count($products) >= 100) {
                                ?>
                                <li><a href="#100" >100</a></li>
        <?php
    }
    if (count($products) >= 200) {
        ?>
                                <li><a href="#200" >200</a></li>
        <?php
    }
    ?>
                        </ul>
                    </div>
                    <div class="clear"></div>
                    <div id="pagePositionNum"></div>
                    <div id="Pagination"></div>
                    <div id="gotoPage">
                        <input type="text" size="10" />
                        <button value="Go" >Go</button>
                    </div>
    <?php
}
?>
                <div class="clear"></div>
            </div>
        </div>
        <!--Start slider--><!--End Slider-->
    </div>              
    <div class="paging"> </div>
</div>

<?php echo $this->element('home/browse_search_js'); ?>